package com.tencent.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.tencent.User;
import com.tencent.block.OrderBlockHandler;
import com.tencent.feign.UserFallBack;
import com.tencent.feign.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserService userService;

    @GetMapping("/findUserById/{id}")
    @SentinelResource(value = "order-findUserById",
                      blockHandler = "findUserByIdHandler",
                      blockHandlerClass = OrderBlockHandler.class,
                      fallback = "findUserByIdFallback",
                      fallbackClass = UserFallBack.class)
    public User findUserById(@PathVariable("id") Long id){
        int a = 1/0;
        return userService.findUserById(id);
    }

//    // 限流方法必须要求传入一个BlockException
//    public User findUserByIdHandler(@PathVariable("id") Long id, BlockException e){
//        return new User(-1L, "限流了", "你们不要再挤了");
//    }

}
